/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.cid.jsfproducts.controllerbeans;

import edu.chl.cid.jsfproducts.Product;
import edu.chl.cid.jsfproducts.modelbeans.ShoppingCartModelBean;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Mikey
 */
@ManagedBean
@ViewScoped
public class ViewCartControllerBean {
    
    @ManagedProperty("#{shoppingCartModelBean}")
    private ShoppingCartModelBean cart;

    /** Creates a new instance of ViewCartControllerBean */
    public ViewCartControllerBean() {
    }
    
    public List<Product> getProductsInCart() {
        return cart.getProducts();
    }
    
    public ShoppingCartModelBean getCart() {
        return cart;
    }
    
    public void setCart(ShoppingCartModelBean cart) {
        this.cart = cart;
    }
    
    
    
    public String emptyCart() {
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().
                getExternalContext().getRequest();
        request.getSession().invalidate();
        return "onEmptyCart";
    }
}
